package org.geekbang.time.mathbasicthought.lesson1_binary;

import java.math.BigInteger;

public class BinaryToDecimal {

    public static void main(String[] args) {
        int decimalSource = 53;
        System.out.println(decimalToBinary(decimalSource));
        System.out.println(binaryToDecimal(decimalToBinary(decimalSource)));
    }

    public static String decimalToBinary(int decimalSource) {
        BigInteger bigInteger = new BigInteger(String.valueOf(decimalSource));
        return bigInteger.toString(2);
    }

    public static int binaryToDecimal(String binarySource) {
        BigInteger bigInteger = new BigInteger(binarySource, 2);
        return Integer.parseInt(bigInteger.toString());
    }
}
